package com.two.screen.water.balance.ui.activity.base

import android.annotation.SuppressLint
import android.os.Build
import com.google.android.material.appbar.AppBarLayout
import androidx.appcompat.widget.Toolbar
import android.widget.ImageView
import android.widget.TextView
import butterknife.BindView
import com.gyf.barlibrary.ImmersionBar
import com.two.screen.water.balance.R


/**
 * 创建者     Noel
 * 创建时间   2017/12/26 11:57
 */
@SuppressLint("NonConstantResourceId")
abstract class BaseToolbarActivity : BaseActivity() {
    @BindView(R.id.base_toolbar_center_title_tv) protected lateinit var mTitleTv: TextView
    @BindView(R.id.base_toolbar_right_title_tv) protected lateinit var mRightTitleTv: TextView
    @BindView(R.id.base_toolbar_right_iv) protected lateinit var mRightIconIv: ImageView
    @BindView(R.id.base_toolbar_back_iv) protected lateinit var mBackIv: ImageView
    @BindView(R.id.appbar_layout) protected lateinit var mAppBar: AppBarLayout
    @BindView(R.id.toolbar) protected lateinit var mToolbar: Toolbar


    override fun initOther() {
        super.initOther()
        setSupportActionBar(mToolbar)
        /*if (canBack()) {
            val actionBar = supportActionBar
            if (actionBar != null) {
                actionBar.run {
                    setDisplayHomeAsUpEnabled(true)
                    setDisplayShowTitleEnabled(false)
                }
                mToolbar.setNavigationOnClickListener { goBack() }
            }
        }*/
        mBackIv.setOnClickListener({ goBack() })
        if (Build.VERSION.SDK_INT >= 21) {
            mAppBar.elevation = setElevation()
        }
    }

    override fun initImmersionBar() {
        super.initImmersionBar()
        ImmersionBar.setTitleBar(this, mToolbar)
        mImmersionBar?.keyboardEnable(true)
            ?.init()
    }


    protected open fun canBack(): Boolean = true
    protected open fun setElevation(): Float = 10.6f
}